package com.cssy.yd.logic.web;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cssy.authority.service.IScUserRolewhPlaceService;
import com.cssy.yd.basic.service.IBasicStorageService;
import com.cssy.yd.logic.entity.LogicSailingDate;
import com.cssy.yd.logic.entity.ReportCqtjDO;
import com.cssy.yd.logic.entity.ReportCqtjItemDO;
import com.cssy.yd.logic.service.ILogicPoService;
import com.cssy.yd.logic.service.ILogicPoWareService;
import com.cssy.yd.logic.service.ILogicWhAffService;
import com.cssy.yd.logic.service.ILogicWhAffStockService;
import com.cssy.yd.logic.util.SqlUtil;
import com.cssy.yd.logic.vo.LogicPoVO;
import com.cssy.yd.logic.vo.ProfitandlossVO;
import com.plat.helper.JqGridHandler;
import com.plat.helper.SearchConditions;
import com.plat.helper.SearchResult;
import com.plat.util.DateUtil;
import com.plat.util.DateUtils;
import com.plat.util.ExcelUtil;
import com.plat.util.json.OutJsonGrid;

@Controller
@RequestMapping("/yd/report")
public class ReportController {

	private static final String MANAGERGX = "/yd/logic/storageDeatils/ManagerDayGx";
	private static final String MANAGERBS = "/yd/logic/profitandloss/ProFitandLossReport";
	private static final String MANAGERPO = "/yd/logic/po/PoReport";
	private static final String MANAGERG = "/yd/logic/Report/SailingDateManager";
	private static final String WHMANAGER = "/yd/logic/Report/CqtjWhManager";
	private static final String WLMANAGER = "/yd/logic/Report/CqtjManager";
	private static final String MANAGERGKC = "/yd/logic/DailyInventory/StockManager";
	@Resource(name = "logicWhAffService")
	private ILogicWhAffService logicWhAffService;
	
	@Resource(name = "basicwhService")
	private IBasicStorageService basicwhService;

	@Resource(name = "logicPoService")
	private ILogicPoService logicPoService;

	@Resource(name = "scUserRolePlaceService")
	private IScUserRolewhPlaceService scUserRolePlaceService;

	@Resource(name="logicWhAffStockService")
	private ILogicWhAffStockService logicWhAffStockService;
	
	@Resource(name="logicPoWareService")
	private ILogicPoWareService logicPoWareService ;
	@RequestMapping("/gx")
	public String manager(HttpServletRequest request,
			HttpServletResponse response) {
		return MANAGERGX;
	}

	@RequestMapping("/bs")
	public String bsmanager(HttpServletRequest request,
			HttpServletResponse response) {
		return MANAGERBS;
	}

	@RequestMapping("/pocq")
	public String pomanager(HttpServletRequest request,
			HttpServletResponse response) {
		return MANAGERPO;
	}

	@RequestMapping("/manager")
	public String cqmanager(HttpServletRequest request,
			HttpServletResponse response) {
		return MANAGERG;
	}
	@RequestMapping("/cqtjmanager")
	public String cqtjmanager(HttpServletRequest request,
			HttpServletResponse response ,Model model) {
		String containMoney = request.getParameter("containMoney");
		List<String> lists = basicwhService.getStorageinfoAndArea();
		model.addAttribute("lists", lists);
		model.addAttribute("wh",SqlUtil.sqlUtil.roleWH(request, scUserRolePlaceService));
		if("true".equals(containMoney)){
			return WLMANAGER;
		}else{
		return WHMANAGER;
		}
	}
	
	@RequestMapping("/cqtjlist")
	public void cqtjlist(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		JqGridHandler hander=new JqGridHandler(request);
		 SearchConditions scs = new SearchConditions();
//		 hander.getWheres(scs);	
//		 Map<String,Object> sqlMap = SqlUtil.sqlUtil.roleWhSqlFilter(request, scUserRolePlaceService,"whCode");
//		 scs.addCondition((String)sqlMap.get("option"), (List)sqlMap.get("roleWhList"));
		 SearchResult result= new SearchResult(scs);
		 ReportCqtjDO reportCqtjDO = new ReportCqtjDO();
		 String name = hander.getQueryValue("name");
		 String yesr = hander.getQueryValue("yesr");
		 reportCqtjDO.setName(name);
		 reportCqtjDO.setYesr(yesr);
		 List<ReportCqtjItemDO> reportCqtjItemDOlist= logicPoWareService.findListByReportCqtjDO(reportCqtjDO);
		 result.setResults(reportCqtjItemDOlist);
		 OutJsonGrid out=new OutJsonGrid(result);
		 out.printJSon(response);
	}
	@RequestMapping("/cqtjwhlist")
	public void cqtjwhlist(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		JqGridHandler hander=new JqGridHandler(request);
		 SearchConditions scs = new SearchConditions();
//		 hander.getWheres(scs);	
//		 Map<String,Object> sqlMap = SqlUtil.sqlUtil.roleWhSqlFilter(request, scUserRolePlaceService,"whCode");
//		 scs.addCondition((String)sqlMap.get("option"), (List)sqlMap.get("roleWhList"));
		 SearchResult result= new SearchResult(scs);
		 ReportCqtjDO reportCqtjDO = new ReportCqtjDO();
		 String name = hander.getQueryValue("name");
		 String yesr = hander.getQueryValue("yesr");
		 reportCqtjDO.setName(name);
		 reportCqtjDO.setYesr(yesr);
		 List<ReportCqtjItemDO> reportCqtjItemDOlist= logicPoWareService.findListByWh(reportCqtjDO);
		 result.setResults(reportCqtjItemDOlist);
		 OutJsonGrid out=new OutJsonGrid(result);
		 out.printJSon(response);
	}
	@RequestMapping("/cqtjexportExcel")
	public void cqtjexportExcel(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		ReportCqtjDO reportCqtjDO = new ReportCqtjDO();
		String name = request.getParameter("name");
		String yesr = request.getParameter("yesr");
		name=new String(name.trim().getBytes("ISO-8859-1"), "UTF-8"); 
		yesr=new String(yesr.trim().getBytes("ISO-8859-1"), "UTF-8"); 
		if(!"".equals(name)){
			reportCqtjDO.setName(name);
		}
		if(!"".equals(yesr)){
			reportCqtjDO.setYesr(yesr);
		}
		String iswh = request.getParameter("iswh");
		List<ReportCqtjItemDO> reportCqtjItemDOlist= new ArrayList<ReportCqtjItemDO>();
		if("NO".equals(iswh)){
			reportCqtjItemDOlist.addAll(logicPoWareService.findListByReportCqtjDO(reportCqtjDO));
		}else{
			reportCqtjItemDOlist.addAll(logicPoWareService.findListByWh(reportCqtjDO));
		}
		 
		 request.setAttribute("reportCqtjItemDOlist", reportCqtjItemDOlist);
		 request.setAttribute("length", reportCqtjItemDOlist.size());
		
		 response.setContentType("application/vnd.ms-excel");
		response.setHeader("Content-disposition", "attachment;filename=export_" + System.currentTimeMillis() + ".xls");
		 RequestDispatcher dispatcher = request.getRequestDispatcher("/views/printer/expostAPCqtj.jsp");
			
			dispatcher.forward(request, response);
	}
	@RequestMapping("/gxlist")
	public void gxlist(HttpServletRequest request, HttpServletResponse response) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.getWheres(scs);
		String d = hander.getQueryValue("a.dctime");
		String creategsname = hander.getQueryValue("a.creategsname");
		Map map = new HashMap();
		if (d != null && !"".equals(d)) {
			map.put("dctime", d + " 00:00:00");
			map.put("dctime1", d + " 23:59:59");
		} else {
			map.put("dctime", sdf.format(new Date()) + " 00:00:00");
			map.put("dctime1", sdf.format(new Date()) + " 23:59:59");
		}
		if (creategsname != null && !"".equals(creategsname)) {
			map.put("creategsname", "%" + creategsname + "%");
		}
		map.put("limitClause", scs.getLimitClause());
//		SearchResult result = logicWhAffService.findGxAll(map);
//		OutJsonGrid out = new OutJsonGrid(result);
//		out.printJSon(response);
	}


	@RequestMapping("/polist")
	public void polist(HttpServletRequest request, HttpServletResponse response) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.getWheres(scs);
		String d = hander.getQueryValue("dgrq");
		String whname = hander.getQueryValue("whname");
		Map map = new HashMap();
		if (d != null && !"".equals(d)) {
			map.put("dgrq", d);
		} else {
			map.put("dgrq", DateUtils.dateToString(new Date(), "yyyy-MM-dd"));
		}
		if (whname != null && !"".equals(whname)) {
			map.put("whname", whname);
		}
		map.put("limitClause", scs.getLimitClause());
		try {
			SearchResult result = null;
					//logicPoService.findByExample(map);
			List<LogicPoVO> list = result.getResults();
			List<LogicPoVO> list1 = new ArrayList<LogicPoVO>();
			if (list.size() > 0) {
				for (int i = 0; i < list.size(); i++) {
					if (i == 0) {
						list.get(i).setKytl(
								list.get(i).getYdengquantity()
										/ list.get(i).getRyl());
						list.get(i).setYjsyrq(
								DateUtils.dateToString(DateUtil.getPlusTime(
										list.get(i).getDgrq(), list.get(i)
												.getKytl()), "yyyy-MM-dd"));
						list.get(i).setYjrksj(
								DateUtils.dateToString(DateUtil.getPlusTime(
										list.get(i).getDgrq(), list.get(i)
												.getFxts()), "yyyy-MM-dd"));
					} else {
						list.get(i).setKytl(
								list.get(i).getYdengquantity()
										/ list.get(i).getRyl());
						list.get(i).setYjrksj(
								DateUtils.dateToString(DateUtil.getPlusTime(
										list.get(i).getDgrq(), list.get(i)
												.getFxts()), "yyyy-MM-dd"));
						if (list.get(i).getName()
								.equals(list.get(i - 1).getName())) {
							list.get(i).setYjsyrq(list.get(i - 1).getYjsyrq());
							int ts = DateUtil.getDateByDaySumDay(DateUtils
									.stringToDate(list.get(i).getYjrksj()),
									DateUtils.stringToDate(list.get(i - 1)
											.getYjsyrq()));
							if (DateUtils.stringToDate(list.get(i).getYjrksj())
									.before(DateUtils.stringToDate(list.get(
											i - 1).getYjsyrq()))) {
								list.get(i).setYdgsl((double) ts);
							} else {
								list.get(i).setYdgsl(-(double) ts);
							}
							list.get(i).setZtsl(
									list.get(i).getRyl()
											* list.get(i).getYdgsl());
						} else {
							list.get(i).setYjsyrq(
									DateUtils.dateToString(DateUtil
											.getPlusTime(list.get(i).getDgrq(),
													list.get(i).getKytl()),
											"yyyy-MM-dd"));
						}
					}
					list1.add(list.get(i));
				}
			}
			result.setResults(list1);
			OutJsonGrid out = new OutJsonGrid(result);
			out.printJSon(response);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	
	/**
	 * 报损导出
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/poexportExcel")
	public void poportExcelDay(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.setFilters(new String(request.getParameter("filters").getBytes(
				"ISO-8859-1"), "UTF-8")); // 转码
		hander.getWheres(scs);
		String d = hander.getQueryValue("dgrq");
		String whname = hander.getQueryValue("whname");
		
		Map map = new HashMap();
		if (d != null && !"".equals(d)) {
			map.put("dgrq", d);
		} else {
			map.put("dgrq", DateUtils.dateToString(new Date(), "yyyy-MM-dd"));
		}
		if (whname != null && !"".equals(whname)) {
			map.put("whname", whname);
		}
		SearchResult result = null;
				//logicPoService.findByExample(map);
		List<LogicPoVO> list = result.getResults();
		List<LogicPoVO> list1 = new ArrayList<LogicPoVO>();
		if (list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				if (i == 0) {
					list.get(i).setKytl(
							list.get(i).getYdengquantity()
									/ list.get(i).getRyl());
					list.get(i).setYjsyrq(
							DateUtils.dateToString(DateUtil.getPlusTime(
									list.get(i).getDgrq(), list.get(i)
											.getKytl()), "yyyy-MM-dd"));
					list.get(i).setYjrksj(
							DateUtils.dateToString(DateUtil.getPlusTime(
									list.get(i).getDgrq(), list.get(i)
											.getFxts()), "yyyy-MM-dd"));
				} else {
					list.get(i).setKytl(
							list.get(i).getYdengquantity()
									/ list.get(i).getRyl());
					list.get(i).setYjrksj(
							DateUtils.dateToString(DateUtil.getPlusTime(
									list.get(i).getDgrq(), list.get(i)
											.getFxts()), "yyyy-MM-dd"));
					if (list.get(i).getName()
							.equals(list.get(i - 1).getName())) {
						list.get(i).setYjsyrq(list.get(i - 1).getYjsyrq());
						int ts = DateUtil.getDateByDaySumDay(DateUtils
								.stringToDate(list.get(i).getYjrksj()),
								DateUtils.stringToDate(list.get(i - 1)
										.getYjsyrq()));
						if (DateUtils.stringToDate(list.get(i).getYjrksj())
								.before(DateUtils.stringToDate(list.get(
										i - 1).getYjsyrq()))) {
							list.get(i).setYdgsl((double) ts);
						} else {
							list.get(i).setYdgsl(-(double) ts);
						}
						list.get(i).setZtsl(
								list.get(i).getRyl()
										* list.get(i).getYdgsl());
					} else {
						list.get(i).setYjsyrq(
								DateUtils.dateToString(DateUtil
										.getPlusTime(list.get(i).getDgrq(),
												list.get(i).getKytl()),
										"yyyy-MM-dd"));
					}
				}
				list1.add(list.get(i));
			}
		ExcelUtil
				.toExcel(
						list1,
						"抵港日期:dgrq┋品牌:brand┋名称:name┋放行天数:fxts┋库存:ydengquantity┋港在途:quantity┋合计:faliaoquantity┋日用量:ryl┋可用天数:kytl┋预计入库日期:yjrksj┋可用至日期:yjsyrq┋库存天数:ydgsl┋预计缺口数量:ztsl",
						"损益表", response);
	}
	}
	
	
	
//	@RequestMapping("/snlist")
//	public String wplist(HttpServletRequest request, HttpServletResponse response,Model model)
//			throws Exception {
//		JqGridHandler hander = new JqGridHandler(request);
//		SearchConditions scs = new SearchConditions();
//		hander.getWheres(scs);
////		SearchResult result = logicWhAffStockService.findListByStockNumber(scs);
////		List<LogicStockNumber> list = result.getResults();
//		Map<String,Double> map  = new HashMap<String,Double>();
////		for (LogicStockNumber logicStockNumber : list) {
////			if(map == null || map.isEmpty()){
////				map.put(logicStockNumber.getHubname(), logicStockNumber.getQuantity());
////			}else{
////				boolean flag = countMaterial(map,logicStockNumber.getHubname());
////				if(flag){
////					map.put(logicStockNumber.getHubname(), map.get(logicStockNumber.getHubname())== null ?0:map.get(logicStockNumber.getHubname())+(logicStockNumber.getQuantity() == null ?0:logicStockNumber.getQuantity()));
////				}else{
////					map.put(logicStockNumber.getHubname(), logicStockNumber.getQuantity() == null ?0:logicStockNumber.getQuantity());
////				}
////			}
////		}
//		double mapCount = 0.0;//仓库存量合计
//		for (Object obj : map.keySet().toArray()) {
//			String key = (String)obj;
//			if(key.equals("惠通")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("沈阳")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("胜达")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("凯晟")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("青岛中外运")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("西安茂陵")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("新疆")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("重庆振强")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("中远")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("上海芝冲")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("上海沪乐")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("华瑞")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("象屿太平")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("宏力")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("新天地")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("郑州中储")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("武汉")){
//				mapCount +=map.get(key);
//			}
//			if(key.equals("重庆")){
//				mapCount +=map.get(key);
//			}
//		}
//		
//		
//		
//		Map<String, Double> rcMap = new HashMap<String, Double>();
////		for (LogicStockNumber rczt : list) {
////			if(map == null || map.isEmpty()){
////				map.put(rczt.getHubname(), rczt.getBhgquantity());
////			}else{
////				boolean flag = countMaterial(rcMap,rczt.getHubname());
////				
////				if(flag){
////					rcMap.put(rczt.getHubname(), rcMap.get(rczt.getHubname())== null ?0:rcMap.get(rczt.getHubname())+(rczt.getBhgquantity() == null ?0:rczt.getBhgquantity()));
////				}else{
////					rcMap.put(rczt.getHubname(), rczt.getBhgquantity() == null ?0:rczt.getBhgquantity());
////				}
////			}
////		}
//		double rcmapCount = 0.0;//入仓在途小计
//		for (Object obj : rcMap.keySet().toArray()) {
//			String key = (String)obj;
//			if(key.equals("惠通")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("沈阳")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("胜达")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("凯晟")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("青岛中外运")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("西安茂陵")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("新疆")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("重庆振强")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("中远")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("上海芝冲")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("上海沪乐")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("华瑞")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("象屿太平")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("宏力")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("新天地")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("郑州中储")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("武汉")){
//				rcmapCount +=rcMap.get(key);
//			}
//			if(key.equals("重庆")){
//				rcmapCount +=rcMap.get(key);
//			}
//			
//		}
////		List<LogicUseDays> udList = logicWhAffStockService.getUseDays();
////		Map<String,Double> udMap  = new HashMap<String,Double>();
////		double udListCount = 0.0;//日用量合计
////		for (LogicUseDays logicUseDays : udList) {
////			if("哈尔滨港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////					if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////						udMap.put("哈尔滨港口", (map.get("惠通")==null ? 0.0 : map.get("惠通").doubleValue())/logicUseDays.getRyl().doubleValue());
////					}else{
////						udMap.put("哈尔滨港口", 0.0);
////					}
////			}
////			if("大连港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("大连港口", (map.get("沈阳")==null ? 0.0 : map.get("沈阳").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("大连港口", 0.0);
////				}
////			}
////			if("天津港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("天津港口", (map.get("胜达")==null ? 0.0 : map.get("胜达").doubleValue()) + (map.get("凯晟")==null ? 0.0 : map.get("凯晟").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("天津港口", 0.0);
////				}
////			}
////			if("青岛港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("青岛港口", (map.get("青岛中外运")==null ? 0.0 : map.get("青岛中外运").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("青岛港口", 0.0);
////				}
////			}
////			if("西安港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("西安港口", (map.get("西安茂陵")==null ? 0.0 : map.get("西安茂陵").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("西安港口", 0.0);
////				}
////			}
////			if("新疆港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("新疆港口", (map.get("新疆")==null ? 0.0 : map.get("新疆").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("新疆港口", 0.0);
////				}
////			}
////			if("成都港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("成都港口", (map.get("重庆振强")==null ? 0.0 : map.get("重庆振强").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("成都港口", 0.0);
////				}
////			}
////			if("南京港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("南京港口", (map.get("中远")==null ? 0.0 : map.get("中远").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("南京港口", 0.0);
////				}
////			}
////			if("上海港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("上海港口", (map.get("上海芝冲")==null ? 0.0 : map.get("上海芝冲").doubleValue()) + (map.get("上海沪乐")==null ? 0.0 : map.get("上海沪乐").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("上海港口", 0.0);
////				}
////			}
////			if("杭州港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("杭州港口", (map.get("华瑞")==null ? 0.0 : map.get("华瑞").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("杭州港口", 0.0);
////				}
////			}
////			if("厦门港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("厦门港口", (map.get("象屿太平")==null ? 0.0 : map.get("象屿太平").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("厦门港口", 0.0);
////				}
////			}
////			if("广州港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("广州港口", (map.get("宏力")==null ? 0.0 : map.get("宏力").doubleValue()) + (map.get("新天地")==null ? 0.0 : map.get("新天地").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("广州港口", 0.0);
////				}
////			}
////			if("郑州港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("郑州港口", (map.get("郑州中储")==null ? 0.0 : map.get("郑州中储").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("郑州港口", 0.0);
////				}
////			}
////			if("武汉港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("武汉港口", (map.get("武汉港口")==null ? 0.0 : map.get("武汉港口").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("武汉港口", 0.0);
////				}
////			}
////			if("重庆港口".equals(logicUseDays.getGkName())){
////				udListCount += logicUseDays.getRyl();
////				if(logicUseDays.getRyl() != null &&  logicUseDays.getRyl()!=0){
////					udMap.put("重庆港口", (map.get("重庆")==null ? 0.0 : map.get("重庆").doubleValue())/logicUseDays.getRyl().doubleValue());
////				}else{
////					udMap.put("重庆港口", 0.0);
////				}
////			}
////			
////		}
////		double udMapCount = 0.0;//使用天数合计
////		for (Object obj : udMap.keySet().toArray()) {
////			String key = (String)obj;
////			if(key.equals("惠通")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("沈阳")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("胜达")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("凯晟")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("青岛中外运")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("西安茂陵")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("新疆")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("重庆振强")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("中远")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("上海芝冲")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("上海沪乐")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("华瑞")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("象屿太平")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("宏力")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("新天地")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("郑州中储")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("武汉")){
////				udMapCount +=udMap.get(key);
////			}
////			if(key.equals("重庆")){
////				udMapCount +=udMap.get(key);
////			}
////		}
////		
////		
////		
////		Map<String, Double> rcCountMap = new HashMap<String, Double>();
////		for (Object obj : map.keySet().toArray()) {
////			String key = (String)obj;
////			boolean flag = countMaterial(rcMap,key);
////			if(flag){
////				rcCountMap.put(key, (map.get(key)== null ?0:map.get(key))+(rcMap.get(key)== null ?0:rcMap.get(key)));
////			}
////		}
////		double rcCount = 0.0;//库存及在途 总计
////		for (Object obj : rcCountMap.keySet().toArray()) {
////			String key = (String)obj;
////			rcCount +=rcCountMap.get(key);
////		}
////		
////		
////		List<LogicImportShipment> isList = logicWhAffStockService.findByImportShipment();
////		Map<String, String> isMap1 = new HashMap<String, String>();
////		for (LogicImportShipment logicImportShipment : isList) {
////				if(isMap1 == null || isMap1.isEmpty()){
////					isMap1.put(logicImportShipment.getWhname(), DateUtils.dateToString(logicImportShipment.getDgrq(), "yyyy-MM-dd"));
////				}else{
////					boolean flag = countMaterial(isMap1,logicImportShipment.getWhname());
////					
////					if(flag){
////						isMap1.put(logicImportShipment.getWhname(), isMap1.get(logicImportShipment.getWhname())+"/"+DateUtils.dateToString(logicImportShipment.getDgrq(), "yyyy-MM-dd"));
////					}else{
////						isMap1.put(logicImportShipment.getWhname(), DateUtils.dateToString(logicImportShipment.getDgrq(), "yyyy-MM-dd"));
////					}
////				}
////		}
////		int count = isMap1.size();
//		
////		Double gcListCount = 0.0;//国产采购量小计
////		List<LogicGccgl> gclList = logicWhAffStockService.findByGccglExample();
////		for (LogicGccgl logicGccgl : gclList) {
////			gcListCount += logicGccgl.getQuantity();
////		}
//		
//		
////		List<LogicDamnify> dflList = logicWhAffStockService.findBylogicDamnifyExample();
////		Map<String, Double> dfMap = new HashMap<String, Double>();
////		for (LogicDamnify logicDamnify : dflList) {
////			if(dfMap == null || dfMap.isEmpty()){
////				dfMap.put(logicDamnify.getWhname(), logicDamnify.getHealthycount());
////			}else{
////				boolean flag = countMaterial(dfMap,logicDamnify.getWhname());
////				if(flag){
////					dfMap.put(logicDamnify.getWhname(), dfMap.get(logicDamnify.getWhname())==null?0:dfMap.get(logicDamnify.getWhname())+logicDamnify.getHealthycount());
////				}else{
////					dfMap.put(logicDamnify.getWhname(), logicDamnify.getHealthycount());
////				}
////			}
////		}
////		double dfMapCount = 0.0;//使用天数合计
////		for (Object obj : dfMap.keySet().toArray()) {
////			String key = (String)obj;
////			if(key.equals("惠通")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("沈阳")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("胜达")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("凯晟")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("青岛中外运")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("西安茂陵")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("新疆")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("重庆振强")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("中远")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("上海芝冲")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("上海沪乐")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("华瑞")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("象屿太平")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("宏力")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("新天地")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("郑州中储")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("武汉")){
////				dfMapCount +=dfMap.get(key);
////			}
////			if(key.equals("重庆")){
////				dfMapCount +=dfMap.get(key);
////			}
////		}
////		
////		
////		
////		
////		List<LogicFlavoring> fiList = logicWhAffStockService.findByFlavoringExample();
////		List<LogicFlavoring> fiList2 =  new ArrayList<LogicFlavoring>();
////		Map<String, List> fiMap = new HashMap<String, List>();
////		for (LogicFlavoring logicFlavoring : fiList) {
////			if(fiList2 == null){
////				fiList2.add(logicFlavoring);
////			}else{
////				boolean flag = countFlavoring(fiList2,logicFlavoring);
////				if(flag){
////					fiList2.add(logicFlavoring);
////				}
////			}
////		}
//////		for (int i = 0; i < fiList.size(); i++) {
//////			LogicFlavoring logicFlavoring = fiList.get(i);
//////			System.out.println("仓库名称:"+logicFlavoring.getCkName()+",物料名曾："+logicFlavoring.getWlname()+",品牌:"+logicFlavoring.getBrand());
//////			if(fiList2 == null){
//////				fiList2.add(logicFlavoring);
//////			}else{
//////				boolean flag = countFlavoring(fiList2,logicFlavoring,1);
//////				if(flag){
//////					boolean bl = countFlavoring(fiList2,logicFlavoring,2);
//////					if(!bl){
//////						fiList2.add(logicFlavoring);
//////					}else{
//////						if(i > 0 ){
//////							fiMap.put(fiList.get(i-1).getCkName(), fiList2);
//////						}
//////						fiList2 = new ArrayList<LogicFlavoring>();
//////						fiList2.add(logicFlavoring);
//////					}
//////					
//////				}
//////			}
//////		}
//////		for (Object obj : fiMap.keySet().toArray()) {
//////			String key = (String)obj;
//////			List<LogicFlavoring> fiList3 =  new ArrayList<LogicFlavoring>();
//////			System.out.println("我的键:"+key);
//////			fiList3 = fiMap.get(key);
//////			for (LogicFlavoring logicFlavoring : fiList3) {
//////				System.out.println("仓库名称:"+logicFlavoring.getCkName()+",物料名曾："+logicFlavoring.getWlname()+",品牌:"+logicFlavoring.getBrand());
//////			}
//////		}
////		
////	
////		model.addAttribute("list", list);
////		model.addAttribute("map", map);
////		model.addAttribute("udList", udList);
////		model.addAttribute("udMap", udMap);
////		model.addAttribute("rcMap", rcMap);
////		model.addAttribute("rcCountMap", rcCountMap);
////		model.addAttribute("isMap1", isMap1);
////		model.addAttribute("count", count);
////		model.addAttribute("gclList", gclList);
////		model.addAttribute("dflList", dflList);
////		model.addAttribute("dfMap", dfMap);
////		
////		model.addAttribute("mapCount", mapCount);
////		model.addAttribute("rcmapCount", rcmapCount);
////		model.addAttribute("udListCount", udListCount);
////		model.addAttribute("udMapCount", udMapCount);
////		model.addAttribute("rcCount", rcCount);
////		model.addAttribute("gcListCount", gcListCount);
////		model.addAttribute("dfMapCount", dfMapCount);
////		model.addAttribute("fiList2", fiList2);
////		return MANAGERGKC;
////	}
////	
////	
////	public static boolean countMaterial(Map map,String name){
////		boolean flag  =false;
////		for (Object obj : map.keySet().toArray()) {
////			String key = (String)obj;
////			if(key != null && name != null){
////				if(key.equals(name)){
////					flag = true;
////				}
////			}
////		}
////		return flag;
////	}
////	
////	public static boolean countFlavoring(List<LogicFlavoring> list,LogicFlavoring logicFlavoring){
////		boolean flag  =true;
////			for (LogicFlavoring logicFlavoring2 : list) {
////				if(logicFlavoring2.getCkName().equals(logicFlavoring.getCkName()) && logicFlavoring2.getWlname().equals(logicFlavoring.getWlname()) && logicFlavoring2.getBrand().equals(logicFlavoring.getBrand())){
////					flag = false;
////				}
////		}
////		
////		return flag;
////	}
}
